package com.gxa.zhonglong.service.impl;


import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;

import com.gxa.zhonglong.mapper.StoneColorMapper;
import com.gxa.zhonglong.pojo.StoneClarity;
import com.gxa.zhonglong.pojo.StoneColor;
import com.gxa.zhonglong.service.StoneColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneColorService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneColorServiceImpl implements StoneColorService {

    @Autowired
    private StoneColorMapper stoneColorMapper;


    @Override
    public Boolean addStoneColor(StoneColor stoneColor) throws BusinessException {
        StoneColor stoneColor1 = stoneColorMapper.selectStoneColorByCode(stoneColor.getColorCode());
        if (stoneColor1 == null) {
            stoneColorMapper.addStoneColor(stoneColor);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneColor(List<Long> ids) throws BusinessException {
       if(stoneColorMapper.deleteStoneColor(ids)<1){
           throw new BusinessException(ExceptionCode.DELETE_FALSE);
       }
    }

    @Override
    public Boolean updateStoneColor(StoneColor stoneColor) throws BusinessException {
        Boolean aBoolean = stoneColorMapper.updateStoneColor(stoneColor);
        if (aBoolean) {
            return true;
        }
        throw  new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<StoneColor> getStoneColor() {
        List<StoneColor> stoneColors = stoneColorMapper.selectStoneColor();
        return stoneColors;
    }
}
